#include <allegro.h>
#include <stdio.h>

#define GFX_W 800
#define GFX_H 600
#define NB_IMAGES 16

int main() {
struct Personage {
	BITMAP * img_right[NB_IMAGES];
	
	
	float x, y;
	int direction; 
};
typedef struct Personage Personage;
struct plat{
BITMAP * img_plat[NB_IMAGES];
BITMAP * img_platcol[NB_IMAGES];

};
typedef struct plat plat;

      char chemin_background[]="../images/background.bmp";
       char chemin_background_col[]="../images/platcol0.bmp";




BITMAP *Buffer;
	BITMAP *Background=NULL;
	BITMAP *BackgroundCol=NULL;
        BITMAP *Backplat=NULL;
	Personage men;


        BITMAP *BackgroundAccueil=NULL;
        BITMAP *BackgroundWelc=NULL;
        BITMAP *BackgroundGameover=NULL;
        BITMAP *BackgroundChoix=NULL;
        BITMAP *BackgroundCader=NULL;

       
        BITMAP *BackgroundPause=NULL;
        BITMAP *BackgroundCa=NULL;
        BITMAP *BackgroundFin=NULL;
  

        BITMAP *BackgroundC1=NULL;
        BITMAP *BackgroundC2=NULL;
        BITMAP *BackgroundC3=NULL;
        BITMAP *BackgroundCv=NULL;
        BITMAP *BackgroundRe=NULL;



	
SAMPLE *music;
int son_music;
 plat p;
BITMAP* load_background_bmp(char chemin_background[]);
BITMAP* load_background1_bmp(char chemin_background_col[]);
 
	int compteur; float a,c,b; int d,f,e,g,h,k,l,m,n,o,r,s;
 int pix1; int pix2;int pix3; int pix4;

	allegro_init();
if(install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL)) {
allegro_message("Sound Error: %s", allegro_error);
return 1;
}
	if (install_keyboard() == -1) {
		allegro_message("Error! %s", allegro_error);
		return (-1);
	}
	set_color_depth(24);
	if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, GFX_W, GFX_H, 0, 0) != 0) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); /* here’s the command for text mode */
		allegro_message("Unable to initialize video mode!\n%s\n", allegro_error);
		return (1);
	}

	Buffer = create_bitmap(SCREEN_W, SCREEN_H);
	
 

	load_5obza(&men);
	
	Background=load_background_bmp(chemin_background); 
    BackgroundCol= load_background1_bmp( chemin_background_col); 

        BackgroundAccueil=load_bitmap("../images/backgroundac.bmp", NULL);
        BackgroundWelc=load_bitmap("../images/backgroundwe.bmp", NULL);
        BackgroundGameover=load_bitmap("../images/backgroundga.bmp", NULL);
        BackgroundChoix=load_bitmap("../images/backgroundch.bmp", NULL);
        BackgroundCader=load_bitmap("../images/backgroundca.bmp", NULL);

       
        BackgroundPause=load_bitmap("../images/pause.bmp", NULL);
        BackgroundCa=load_bitmap("../images/cader2.bmp", NULL);
        BackgroundFin=load_bitmap("../images/fin.bmp", NULL);


       BackgroundC1=load_bitmap("../images/coeur1.bmp", NULL);
       BackgroundC2=load_bitmap("../images/coeur2.bmp", NULL);
       BackgroundC3=load_bitmap("../images/coeur3.bmp", NULL);
       BackgroundCv=load_bitmap("../images/caderv.bmp", NULL);
       BackgroundRe=load_bitmap("../images/reste.bmp", NULL);

	
    
       load_backplat_bmp(&p);
     init_5obza(&men,&compteur,&a,&c,&b,&d,&f,&e,&g,&h,&k,&l,&m,&n,&o,&r,&s);

music=load_wav("son.wav");


set_volume(100, 100);

  
	
	

 acceuil(BackgroundAccueil,BackgroundWelc,Buffer,&f);


while (h==0) {
 
clear_bitmap(Buffer);


 if (m==0){
son_music=play_sample(music,128,128,1000,0) ;	

 jeux(BackgroundFin,BackgroundC1,BackgroundC2,BackgroundC3,BackgroundCol,Background,Buffer,
p,&men,&pix1,&pix2,&pix3,&pix4,&a,&b,&d,&o,&compteur,&h);



if (key[KEY_ESC]){k=1;m=1;} 
} 

if(k==1) {
	f_pause(BackgroundPause,BackgroundCa,Buffer,&m,&k,&l,&h);
      }



if (men.y>SCREEN_H  ){vie(BackgroundGameover,BackgroundChoix,BackgroundCader,BackgroundRe,BackgroundCv,BackgroundC1,BackgroundC2,BackgroundC3,Buffer,&men,&compteur, &a,&c,&b,&d,&f,&e,&g,&h,&k,&l,&m,&n,&o,&r,&s);

//sauvgard(&men,&compteur,&a,&c,&b,&d,&f,&e,&g,&h,&k,&l,&m,&n,&o,&r,&s);
}



blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
 
		




	}
	
	destroy_5obza(&men);
destroy_background(BackgroundAccueil);
destroy_background(BackgroundWelc);
destroy_background(Background);
destroy_background(BackgroundGameover);
destroy_background(BackgroundChoix);
destroy_background(BackgroundCader);
destroy_background(BackgroundCol);
destroy_background(BackgroundPause);
destroy_background(BackgroundCa); 
destroy_plat(&p);
destroy_bitmap(Buffer);
destroy_background(BackgroundC1);
destroy_background(BackgroundC2);
destroy_background(BackgroundC3);
destroy_background(BackgroundCv);
destroy_background(BackgroundRe);
	return (0);
}
END_OF_MAIN();

